const reactiveMap = new WeakMap()
const reactive = (obj) => {
    return createReactiveObject(obj, false, baseHandlers, collectionHandlers, reactiveMap)
}
//object或者数组的proxy定义
const baseHandlers = {
    get: createGetter(),
    set: createSetter(),
    // deleteProperty,
    // has,
    // ownKeys
};
const collectionHandlers={
    }
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
    if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) {
        //处理过的对象
        return target;
    }
    const existingProxy = proxyMap.get(target);
    // 已经收集过依赖
    if (existingProxy) {
        return existingProxy;
    }
    // const targetType = targetTypeMap(target);
    // if (targetType === 0) {
    //     console.warn("targe is not a reference type");
    //     return target;
    // }
    // const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
    const proxy = new Proxy(target, baseHandlers);
    proxyMap.set(target, proxy);
    return proxy;
}

function targetTypeMap(rawType) {
    switch (rawType) {
        case "Object":
        case "Array":
            return 1 /* COMMON */;
        case "Map":
        case "Set":
        case "WeakMap":
        case "WeakSet":
            return 2 /* COLLECTION */;
        default:
            return 0 /* INVALID */; //非引用类型
    }
}
